// pages/yiliangfang/measureroom.js
Page({
  data: {
    scrollviewheight: '',
    ci_rwdid: '',
    WorksID: '',
    CustomerID: '',
    CatalogID: '',
    baseimageurl: 'http://img0.wenes.cn/Upload/Project/',

    ca_ca_HousingSituation: '',   //房屋现状
    ca_HouseOrientation: '',      //房屋朝向
    ca_OccupyPublicCorridor: '',  //占用公共过道
    ca_isGroundSmooth: '',        //地面是否平整
    ca_CargoDoorHight: '',        //货梯门高度
    ca_CargoDoorWide: '',         //货梯门宽度
    ca_OriginalGroundMaterial: '',//原地面材质
    ca_OriginalTopMaterial: '',   //原顶面材质
    ca_GroundElevation: '',       //地面高差
    ca_SpaceMaxHeight: '',        //原顶面高度
    ca_mainBeamHeight: '',        //主梁下
    ca_SecondaryHeight: '',       //次梁下
    ca_MinimumSprayHeight: '',    //喷淋最低点
    ca_AirConditionerNum: '',     //空调设备个数
    ca_TuyereMinimumHeight: '',   //风口最低点
    ca_StrongBoxNum: '',          //强电箱个数
    ca_WeakBoxNum: '',            //弱电箱个数
    ca_UpWaterSpot: '',           //上水点
    ca_DownWaterSpot: '',         //下水点
    ca_DownWaterSpotSize: '',     //下水管径
    ca_CurtainWallSpacing: '',    //幕墙架间距
    ca_WindowType: '',            //窗户类型
    ca_windowsillHight: '',       //窗台高
    ca_WindowHight: '',           //窗户高

    // 图册数组
    array1: [], // 量房手绘	123
    array2: [], // 周边环境	124
    array3: [], // 室内全景照片	125
    array4: [], // 墙	126
    array5: [], // 顶	127
    array6: [], // 地	128
    array7: [], // 门	129
    array8: [], // 空调	130
    array9: [], // 消防	131
    array10: [],// 强电箱	132
    array11: [],// 弱电箱	133
    array12: [],// 上下水	134

    index1: 0,
    index2: 0,
    index3: 0,
    index4: 0,
    index5: 0,
    index6: 0,
    index7: 0,
    index8: 0,

    arraylist1: ['毛坯', '清水', '旧房改造', '翻新', '精装'],
    arraylist2: ['东西', '南北'],
    arraylist3: ['是', '否'],
    arraylist4: ['是', '否'],
    arraylist5: ['水泥毛坯', '水泥找平', '防静电地板', '地毯', '地砖', '木地板', '塑胶地板'],
    arraylist6: ['水泥毛坯', '矿棉板吊顶', '石膏板吊顶', '铝方通/格栅', '铝扣板吊顶'],
    arraylist7: ['玻璃幕墙', '飘窗', '普通窗', '落地窗'],
  },

  onLoad: function (options) {
    var that = this
    var ci_rwdid = options.ci_rwdid
    that.setData({
      ci_rwdid: options.ci_rwdid,
    })
    // 获取系统高度
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          scrollviewheight: res.screenHeight - 120
        })
      },
    })

    // 数据请求接口一
    that.requestData(that.data.ci_rwdid)
    // 数据请求接口二
    // that.requestPic(that.data.ci_rwdid)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log('onShow')
    var that = this
    that.requestPic(that.data.ci_rwdid)
  },

  requestData: function (ci_rwdid) {
    var that = this
    wx.request({
      url: 'https://api.wenes.cn/JD/GetClientDetailInfo?ci_rwdid=' + that.data.ci_rwdid,
      success: function (res) {
        console.log(res.data.Table)
        var item = res.data.Table[0]
        that.setData({
          WorksID: item.WorksID,
          CustomerID: item.CustomerID,
          ca_ca_HousingSituation: item.ca_ca_HousingSituation,
          ca_HouseOrientation: item.ca_HouseOrientation,
          ca_OccupyPublicCorridor: item.ca_OccupyPublicCorridor,
          ca_isGroundSmooth: item.ca_isGroundSmooth,
          ca_CargoDoorHight: item.ca_CargoDoorHight,
          ca_CargoDoorWide: item.ca_CargoDoorWide,
          ca_OriginalGroundMaterial: item.ca_OriginalGroundMaterial,
          ca_OriginalTopMaterial: item.ca_OriginalTopMaterial,
          ca_GroundElevation: item.ca_GroundElevation,
          ca_SpaceMaxHeight: item.ca_SpaceMaxHeight,
          ca_mainBeamHeight: item.ca_mainBeamHeight,
          ca_SecondaryHeight: item.ca_SecondaryHeight,
          ca_MinimumSprayHeight: item.ca_MinimumSprayHeight,
          ca_AirConditionerNum: item.ca_AirConditionerNum,
          ca_TuyereMinimumHeight: item.ca_TuyereMinimumHeight,
          ca_StrongBoxNum: item.ca_StrongBoxNum,
          ca_WeakBoxNum: item.ca_WeakBoxNum,
          ca_UpWaterSpot: item.ca_UpWaterSpot,
          ca_DownWaterSpot: item.ca_DownWaterSpot,
          ca_DownWaterSpotSize: item.ca_DownWaterSpotSize,
          ca_CurtainWallSpacing: item.ca_CurtainWallSpacing,
          ca_WindowType: item.ca_WindowType,
          ca_windowsillHight: item.ca_windowsillHight,
          ca_WindowHight: item.ca_WindowHight,
        })
      }
    })
  },

  /**
   * 获取照片urls
   */
  requestPic: function (ci_rwdid) {
    var that = this
    // 图册数组
    var array1 = []
    var array2 = []
    var array3 = []
    var array4 = []
    var array5 = []
    var array6 = []
    var array7 = []
    var array8 = []
    var array9 = []
    var array10 = []
    var array11 = []
    var array12 = []
    // 数据请求接口二
    wx.request({
      url: 'https://api.wenes.cn/JD/GetAllImages?ci_rwdid=' + ci_rwdid,
      success: function (res) {
        var length = res.data.Table.length
        console.log(res.data)
        for (var i = 0; i < length; i++) {
          if (res.data.Table[i].CatalogID == '123') {
            array1.push(res.data.Table[i].ImageUrl)
            that.setData({
              array1: array1
            })
          }
          if (res.data.Table[i].CatalogID == '124') {
            array2.push(res.data.Table[i].ImageUrl)
            that.setData({
              array2: array2
            })
          }
          if (res.data.Table[i].CatalogID == '125') {
            array3.push(res.data.Table[i].ImageUrl)
            that.setData({
              array3: array3
            })
          }

          if (res.data.Table[i].CatalogID == '126') {
            array4.push(res.data.Table[i].ImageUrl)
            that.setData({
              array4: array4
            })
          }
          if (res.data.Table[i].CatalogID == '127') {
            array5.push(res.data.Table[i].ImageUrl)
            that.setData({
              array5: array5
            })
          }
          if (res.data.Table[i].CatalogID == '128') {
            array6.push(res.data.Table[i].ImageUrl)
            that.setData({
              array6: array6
            })
          }

          if (res.data.Table[i].CatalogID == '129') {
            array7.push(res.data.Table[i].ImageUrl)
            that.setData({
              array7: array7
            })
          }
          if (res.data.Table[i].CatalogID == '130') {
            array8.push(res.data.Table[i].ImageUrl)
            that.setData({
              array8: array8
            })
          }
          if (res.data.Table[i].CatalogID == '131') {
            array9.push(res.data.Table[i].ImageUrl)
            that.setData({
              array9: array9
            })
          }

          if (res.data.Table[i].CatalogID == '132') {
            array10.push(res.data.Table[i].ImageUrl)
            that.setData({
              array10: array10
            })
          }
          if (res.data.Table[i].CatalogID == '133') {
            array11.push(res.data.Table[i].ImageUrl)
            that.setData({
              array11: array11
            })
          }
          if (res.data.Table[i].CatalogID == '134') {
            array12.push(res.data.Table[i].ImageUrl)
            that.setData({
              array12: array12
            })
          }
        }
      }
    })
  },

  // 点击相册
  uploadimage123: function (e) {
    var that = this
    if (that.data.array1.length > 0) {
      wx.navigateTo({
        url: '../dailiangfang/album?ci_rwdid=' + that.data.ci_rwdid + '&CatalogID=123&WorksID=' + that.data.WorksID + '&CustomerID=' + that.data.CustomerID
      })
    }
    if (that.data.array1 == 0) {
      that.uploadPic('123')
    }
  },
  uploadimage124: function (e) {
    var that = this
    if (that.data.array2.length > 0) {
      wx.navigateTo({
        url: '../dailiangfang/album?ci_rwdid=' + that.data.ci_rwdid + '&CatalogID=124&WorksID=' + that.data.WorksID + '&CustomerID=' + that.data.CustomerID
      })
    }
    if (that.data.array2 == 0) {
      that.uploadPic('124')
    }
  },
  uploadimage125: function (e) {
    var that = this
    if (that.data.array3.length > 0) {
      wx.navigateTo({
        url: '../dailiangfang/album?ci_rwdid=' + that.data.ci_rwdid + '&CatalogID=125&WorksID=' + that.data.WorksID + '&CustomerID=' + that.data.CustomerID
      })
    }
    if (that.data.array3 == 0) {
      that.uploadPic(125)
    }
  },
  uploadimage126: function (e) {
    var that = this
    if (that.data.array4.length > 0) {
      wx.navigateTo({
        url: '../dailiangfang/album?ci_rwdid=' + that.data.ci_rwdid + '&CatalogID=126&WorksID=' + that.data.WorksID + '&CustomerID=' + that.data.CustomerID
      })
    }
    if (that.data.array4 == 0) {
      that.uploadPic('126')
    }
  },
  uploadimage127: function (e) {
    var that = this
    if (that.data.array5.length > 0) {
      wx.navigateTo({
        url: '../dailiangfang/album?ci_rwdid=' + that.data.ci_rwdid + '&CatalogID=127&WorksID=' + that.data.WorksID + '&CustomerID=' + that.data.CustomerID
      })
    }
    if (that.data.array5 == 0) {
      that.uploadPic('127')
    }
  },
  uploadimage128: function (e) {
    var that = this
    if (that.data.array6.length > 0) {
      wx.navigateTo({
        url: '../dailiangfang/album?ci_rwdid=' + that.data.ci_rwdid + '&CatalogID=128&WorksID=' + that.data.WorksID + '&CustomerID=' + that.data.CustomerID
      })
    }
    if (that.data.array6 == 0) {
      that.uploadPic('128')
    }
  },
  uploadimage129: function (e) {
    var that = this
    if (that.data.array7.length > 0) {
      wx.navigateTo({
        url: '../dailiangfang/album?ci_rwdid=' + that.data.ci_rwdid + '&CatalogID=129&WorksID=' + that.data.WorksID + '&CustomerID=' + that.data.CustomerID
      })
    }
    if (that.data.array7 == 0) {
      that.uploadPic('129')
    }
  },
  uploadimage130: function (e) {
    var that = this
    if (that.data.array8.length > 0) {
      wx.navigateTo({
        url: '../dailiangfang/album?ci_rwdid=' + that.data.ci_rwdid + '&CatalogID=130&WorksID=' + that.data.WorksID + '&CustomerID=' + that.data.CustomerID
      })
    }
    if (that.data.array8 == 0) {
      that.uploadPic('130')
    }
  },
  uploadimage131: function (e) {
    var that = this
    if (that.data.array9.length > 0) {
      wx.navigateTo({
        url: '../dailiangfang/album?ci_rwdid=' + that.data.ci_rwdid + '&CatalogID=131&WorksID=' + that.data.WorksID + '&CustomerID=' + that.data.CustomerID
      })
    }
    if (that.data.array9 == 0) {
      that.uploadPic('131')
    }
  },
  uploadimage132: function (e) {
    var that = this
    if (that.data.array10.length > 0) {
      wx.navigateTo({
        url: '../dailiangfang/album?ci_rwdid=' + that.data.ci_rwdid + '&CatalogID=132&WorksID=' + that.data.WorksID + '&CustomerID=' + that.data.CustomerID
      })
    }
    if (that.data.array10 == 0) {
      that.uploadPic('132')
    }
  },
  uploadimage133: function (e) {
    var that = this
    if (that.data.array11.length > 0) {
      wx.navigateTo({
        url: '../dailiangfang/album?ci_rwdid=' + that.data.ci_rwdid + '&CatalogID=133&WorksID=' + that.data.WorksID + '&CustomerID=' + that.data.CustomerID
      })
    }
    if (that.data.array11 == 0) {
      that.uploadPic('133')
    }
  },
  uploadimage134: function (e) {
    var that = this
    if (that.data.array12.length > 0) {
      wx.navigateTo({
        url: '../dailiangfang/album?ci_rwdid=' + that.data.ci_rwdid + '&CatalogID=134&WorksID=' + that.data.WorksID + '&CustomerID=' + that.data.CustomerID
      })
    }
    if (that.data.array12 == 0) {
      that.uploadPic('134')
    }
  },

  // 本地选择图片
  uploadPic: function (CatalogID) {
    var that = this
    console.log('量房onload')
    console.log(that.data.WorksID)
    console.log(CatalogID)
    console.log(that.data.CustomerID)
    wx.chooseImage({
      success: function (res) {
        var tempFilePaths = res.tempFilePaths
        // 上传图片
        wx.uploadFile({
          url: 'https://api.wenes.cn/jd/UploadJDimages',
          filePath: tempFilePaths[0],
          name: 'Filedata',
          formData: {
            'qt': 'upload',
            'type': '1',
            'W': '500',
            'H': '300',
            'HW': 'HW',
            'WorksID': that.data.WorksID,
            'CatalogID': CatalogID,
            'UserId': that.data.CustomerID,
          },
          success: function (res) {
            console.log(res)
            if (res.statusCode == 200) {
              wx.showToast({
                title: '成功',
                icon: 'success',
                duration: 2000
              })
              // 实时刷新
              that.requestPic(that.data.ci_rwdid)
            } else {
              wx.showToast({
                title: '失败',
                icon: 'failure',
                duration: 2000
              })
            }
          }
        })
      },
    })
  },


  // 页面跳转
  surroundings: function () {
    var that = this
    wx.redirectTo({
      url: 'surroundings?ci_rwdid=' + that.data.ci_rwdid + '&WorksID=' + that.data.WorksID + '&CustomerID=' + that.data.CustomerID,
    })
  },
  demand: function () {
    var that = this
    wx.redirectTo({
      url: 'demand?ci_rwdid=' + that.data.ci_rwdid,
    })
  },
  upkeep: function () {
    var that = this
    wx.redirectTo({
      url: 'upkeep?ci_rwdid=' + that.data.ci_rwdid,
    })
  },

})